<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
    <title>管理平台</title>
    <jsp:include page="../../../include/header.jsp"></jsp:include>
      <style type="text/css">
			table td{
			text-align: center;
			}
		 	table th{
			text-align: center;
		 	}
		</style>
</head>
<body>
<div id="wrapper" class="row">

	<!-- 	<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">分公司统计</h1>
			</div>
		</div> -->
			<div class="title-top col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">分公司统计信息</div>
					<div class="panel-body hint">
						<div class="col-xs-2 col-md-2 col-lg-2">分公司总数 :<span class="label label-info" id="goodsCount"></span>${ tolnumber} </div>
						<div class="col-xs-2 col-md-2 col-lg-2">上线审核中分公司 :<span class="label label-info" id="chart1State1"></span>${sjshnumber } </div>
				    	<div class="col-xs-2 col-md-2 col-lg-2">上线分公司总数:<span class="label label-info" id="chart1State2"></span>${sjnumber } </div>
					<%-- <div class="col-xs-2 col-md-2 col-lg-2">下线审核中分公司 :<span class="label label-info" id="chart1State3"></span>${xjshnumber } </div> --%>
						<div class="col-xs-2 col-md-2 col-lg-2">下线分公司总数: <span class="label label-info" id="chart1State4"></span>${xjnumber}</div>
					</div>
				</div>
			</div>
		<!-- 搜索框 -->
			<div class="title-top col-lg-12">
				 <label class="search-label">分公司编号：</label><input type="text" id="sGoodId" class="form-control search-input width200" maxlength="21">
			<%-- 	<label class="search-label">选择分公司：</label>
				  <select id=sStoreId class="selectpicker pull-left p-l-5" multiple="multiple" data-width="12%">
						<c:forEach items="${list }" var="Store">
							<option value="${Store.storeid }">${Store.title }</option>
						</c:forEach>
					</select> --%>
					<label class="search-label">按上线时间：</label>
				<label class="search-label"></label><input type="text" id="sBeginDate" autocomplete="off" value="" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" >
				<label class="search-label">至</label><input type="text" id="sEndDate" autocomplete="off" value="" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" >
				<button class="btn btn-success search-btn" onclick="query();">确定</button>
				<button class="btn btn-success search-btn" onclick="reset();">重置</button>
				 <c:if test="${session.userpopedom.dictStoreTongDoExcel==1}">
						<button onclick="doExcel();" class="btn btn-success pull-right">导出</button>
				</c:if>
					
			</div>
			<div class="clearfix"></div>
			<div class="col-lg-12">
				<div class="col-lg-12">
					<div>
						<div class="text-muted single-line-text pull-left">共 <font color="#428bca" id="dataCount">0</font> 条记录</div>
						
					</div>
					<!-- <div style="float:right;margin-right: 30px;">
						<div class="text-muted single-line-text pull-right">订单量： 日&nbsp;&nbsp;<input type="radio" class="radioItem" id="state1" name="state" value="1" />
						 	&nbsp;&nbsp;周&nbsp;&nbsp;<input type="radio" class="radioItem" id="state2" name="state" value="2" />
						    &nbsp;&nbsp;月&nbsp;&nbsp;<input type="radio" class="radioItem" id="state3" name="state" value="3" /></div>
					</div> -->
				</div>
				<div class="table-responsive panel panel-default">
					<table id="dataTable" class="table table-striped table-hover table-noellipsis table-bordered" style="  overflow:scroll;">
			            <thead>
			                <tr>
								<th width="100px">分公司ID</th>
								<th width="200px">分公司名称</th>
								<th width="100px">主营范围</th>
								<th width="110px">开店时间</th>
								<th width="120px">分公司联系人</th>
								<th width="120px">联系电话</th>
								<th width="100px">产品数量</th>
								<th width="100px">普通订单量</th>
								<th width="100px">普通销售额</th>
								<th width="100px">团购订单量</th>
								<th width="100px">团购销售额</th>
								<th width="100px">分公司状态</th>
								<th width="200px">操作</th>
			                </tr>
			            </thead>
			            <tbody id="dataList"></tbody>
			        </table>
				</div>
		        	<div class="col-lg-12">
		        		<ul id="dataPagination" class="pagination-sm pull-right"></ul>
		        	</div>
			</div>

</div>
<jsp:include page="../../../include/javascripts.jsp"></jsp:include>
<!-- 异步加载下一页数据后，用模板渲染 -->
<script type="text/html" id="dataTpl">
	{{each list as item}}
	<tr id="{{item.id}}" data-id="{{item.id}}">
		<td>{{item.storeid}}</td>
		<td>{{item.title}}</td>
		<td>{{item.scope | flagTransform:1,'常规',2,'团购',3,'常规+团购'}}</td>
		<td>{{item.createtime | dateFormat:'yyyy-MM-dd'}}</td>
		<td>{{item.aname}}</td>
		<td>{{item.aphone}}</td>
		<td>{{item.countGoods}}</td>
		<td>
			<a href="javascript:showOrder('{{item.storeid}}');"><span class="btn">{{item.countNum}}</span></a>	
		</td>
		<td>{{item.countMoney}}</td>
		<td>
			<a href="javascript:showOrdergb('{{item.storeid}}');"><span class="btn">{{item.countNumgb}}</span></a>	
		</td>
		<td>{{item.countMoneygb}}</td>
		 {{if item.qstate==1}}
				{{if item.state==1}}
					<td>上线审核中</td>
				{{else if item.state==2}}
					<td>上线</td>				
               {{else if item.state==3}}
					<td>下线</td>
               {{else if item.state==4}}
					<td>驳回</td>
				{{/if}}
		{{else if item.qstate==2}}           
			 <td>禁货</td>     
		{{else if item.qstate==3}}
			<td>降权</td>
		{{/if}}
		<td>
			<a href="javascript:showStore('{{item.storeid}}');"><span class="btn">查看</span></a>
		</td>
	</tr>
	{{/each}}
</script>
<script type="text/javascript">
var dataPaginator;
$(query);
function query(){
	var sStoreId = $("#sStoreId").val();
	var store;
	if(sStoreId !=null && sStoreId !="" && sStoreId !=undefined){
		store=sStoreId.join("','");
	}
	var params = {
		pageSize:10,
		storeIds:$("#sGoodId").val(),
		//sellerId:$("#sSellerId").val(),
		sStoreId:store,
		sBeginDate:$("#sBeginDate").val(),
		sEndDate:$("#sEndDate").val()
	};
	if(dataPaginator){
		dataPaginator.destroy();
	}
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/dict/store/tong/page",params,function(result){
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
	});
}
function showOrder(storeid){
	window.location.href="${BASE_PATH}/dict/store/tong/goodsOrder?storeid="+storeid;
}
function showOrdergb(storeid){
	window.location.href="${BASE_PATH}/dict/store/tong/goodsOrdergb?storeid="+storeid;
}
$(document).ready(function() {
    $(".radioItem").change(function() {
    	 var $selectedvalue = $("input[name='state']:checked").val();
    		var sStoreId = $("#sStoreId").val();
    		var store;
    		if(sStoreId !=null && sStoreId !="" && sStoreId !=undefined){
    			store=sStoreId.join("','");
    		}
    	 var params = {
   				pageSize:10,
   				storeIds:$("#sGoodId").val(),
   				sStoreId:store,
   				sBeginDate:$("#sBeginDate").val(),
   				sEndDate:$("#sEndDate").val(),
   				date:$selectedvalue
   			};
   			if(dataPaginator){
   				dataPaginator.destroy();
   			}
   			dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/dict/store/tong/xspage",params,function(result){
   				//设置显示最新的数据数量
   				$("#dataCount").html(result.object.totalRow);
   				//根据模板渲染数据并填充
   				$("#dataList").empty().append(template("dataTpl",result.object));
   			});
    });
});
function doExcel(){
	var $selectedvalue = $("input[name='state']:checked").val();
	if($selectedvalue==undefined){
		$selectedvalue =0;
	}
	var storeIds=$("#sGoodId").val(),sStoreId=$("#sStoreId").val(),sBeginDate=$("#sBeginDate").val(),sEndDate=$("#sEndDate").val();
	var store="";
	if(sStoreId !=null && sStoreId !="" && sStoreId !=undefined){
		store=sStoreId.join("','");
	}
	window.location.href="${BASE_PATH}/dict/store/tong/doExcel?storeIds="+storeIds+"&sStoreId="+store+"&sBeginDate="+sBeginDate+"&sEndDate="+sEndDate+"&date="+$selectedvalue;
}
var detailDialog;
function showStore(id){
	detailDialog = Kit.dialog("查看详情","${BASE_PATH}/dict/store/tong/detail?storeid="+id,{closable:true}).open();
}
var editDialog;
function edit(storeid){
	editDialog = Kit.dialog("编辑分公司","${BASE_PATH}/dict/store/tong/toEdit?storeid="+storeid,{closable:true,size:"size-wide:100px"}).open();
};
 
$("#sBeginDate").datetimepicker({
    format: 'yyyy-mm-dd hh:ii:ss',
    minuteStep:1,
    minView:'hour',
    language: 'zh-CN',
    pickerPosition:'bottom-right',
    autoclose:true,
}).on("click",function(){
	var d2=new Date();
	var d=$("#sEndDate").val();
	if(d==""){
		 $("#sBeginDate").datetimepicker("setEndDate",d2);
	}else{
		var d1=new Date(d); 
		d1.setDate(d1.getDate()-1);
		if(d1>d2){
	  	 	 $("#sBeginDate").datetimepicker("setEndDate",d2);
		}else{
			 $("#sBeginDate").datetimepicker("setEndDate",d1);
		}
	}
});

$("#sBeginDate").datetimepicker({
    format: 'yyyy-mm-dd hh:ii:ss',
    minuteStep:1,
    minView:'hour',
    language: 'zh-CN',
    pickerPosition:'bottom-right',
    autoclose:true,
}).on("click",function(){
	var d2=new Date();
	var d=$("#sEndDate").val();
	if(d==""){
		 $("#sBeginDate").datetimepicker("setEndDate",d2);
	}else{
		var d1=new Date(d); 
		d1.setDate(d1.getDate()-1);
		if(d1>d2){
	  	 	 $("#sBeginDate").datetimepicker("setEndDate",d2);
		}else{
			 $("#sBeginDate").datetimepicker("setEndDate",d1);
		}
	}
});

$("#sEndDate").datetimepicker({
    format: 'yyyy-mm-dd hh:ii:ss',
    minuteStep:1,
    minView:'hour',
    language: 'zh-CN',
    autoclose:true,
	}).on("click",function(){
		var d=$("#sBeginDate").val();
		var d1=new Date(d); 
		d1.setDate(d1.getDate()+1); 
		$("#sEndDate").datetimepicker("setStartDate",d1);
	});
	
 $(document).on("click","#sEndDate",function(){
    	$('#sEndDate').datetimepicker('show');
    });

$(document).on("click","#sBeginDate",function(){
	$('#sBeginDate').datetimepicker('show');
});
function reset(){
	$("#sGoodId").val("");$("#sBeginDate").val("");$("#sEndDate").val("");
	$("#sSellerId").val("0");$("#sSellerId").trigger("change");   $("#sState").val("0");$("#sState").trigger("change");
}
</script>
</body>
</html>